﻿using System;
using System.Linq.Expressions;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Com.Model.Cms;
using Com.Bll.Cms;
using System.Collections;

namespace ArticleRefresh
{
    class Program
    {
        static void Main(string[] args)
        {
            #region//插入数据
            //DateTime now = DateTime.Now;
            //int recordCount = 2316;
            //InsertArticle(100000);
            //Console.WriteLine("共插入了{0}行,共耗时:{1}小时",recordCount,(DateTime.Now-now).TotalHours);
            #endregion

            #region//sql查询数据
            //ArticleOperater ao = new ArticleOperater();
            //DateTime now = DateTime.Now;
            //List<Cms_Article> lst = ao.GetArticles("select * from cms_article where articleid=123 order by articleid desc limit 10", new Object[] { });
            //Console.WriteLine(String.Format("sql查询花费{0}秒", (DateTime.Now - now).TotalSeconds));
      
            //foreach (Cms_Article article in lst)
            //{
            //    Console.WriteLine(article.ArticleId);
            //}
            #endregion

            #region//按id 查询
            ArticleOperater ao = new ArticleOperater();
            Cms_Article model = ao.GetArticle(123);
            Console.WriteLine(model.ArticleId);
            #endregion

            #region//Lambda表达式 查询数据
            //ArticleOperater ao = new ArticleOperater();
            //// item => item.ArticleId == 123;
            ////  item => item.ArticleId;
            //DateTime now = DateTime.Now;
            //Expression<Func<Cms_Article, bool>> where = item => item.ArticleId == 123;
            //Expression<Func<Cms_Article, int>> orderBy = item => item.ArticleId;
            //List<Cms_Article> lst = ao.GetArticles(1, 10, where,orderBy);
            //Console.WriteLine(String.Format("Lambda表达式查询花费{0}秒", (DateTime.Now - now).TotalSeconds));
            //foreach (Cms_Article article in lst)
            //{
            //    Console.WriteLine(article.ArticleId);
            //}
            #endregion
            Console.ReadLine();
        }
        public static void InsertArticle(int count)
        {
            ArticleOperater ao = new ArticleOperater();
            for (int i = 0; i < count; i++)
            {
                Cms_Article model = new Cms_Article();
                model.ArticleStateId = 1;
                model.ArticleTypeId = 1;
                model.AuthorId = 1;
                model.CreateDate = DateTime.Now;
                model.CreateUserId = 1;

                model.SourceId = 1;
                model.Seq = i;
                int id = ao.InsertArticle(model);
                Console.WriteLine(String.Format("正在插入第{0}行...",id));
            }
        }
    }
}
